<template>
    <view>
        <!-- 优惠券 -->
        <!-- 
传入参数：
couponArr：优惠券列表
couponCodeStatus：优惠券券码状态
传入方法：
goToCoupon: 跳转至优惠券详情
 -->
        <block name="coupon">
            <view class="temp-coupon-list" v-if="couponArr && couponArr.length > 0">
                <view :class="'temp-coupon-item ' + (couponCodeStatus == 2 || couponCodeStatus == 3 ? 'temp-coupon-offline' : '')" v-for="(item, index) in couponArr" :key="index">
                    <view
                        :class="'temp-coupon-item-left ' + ('origin' + item.couponOrigin)"
                        :style="'color:' + (item.couponOrigin == '0' ? '#ff7303' : '#FF1744') + ';background: ' + (item.couponSource == '2' ? '#ffc4bd' : '') + ';'"
                    >
                        <!-- 优惠券预览图 -->
                        <image style="width: 100%; height: 100%" v-if="'7' == item.couponType && !util.isEmpty(item.pic)" :src="baseurl + '/' + item.pic"></image>
                        <image style="width: 100%; height: 100%" v-else-if="'7' == item.couponType && !util.isEmpty(item.picUrl)" :src="baseurl + '/' + item.picUrl"></image>
                        <image style="width: 100%; height: 100%" v-else-if="'7' == item.couponType" src="/static/image/coupon/default_icon.png"></image>
                        <!-- <image class="temp-coupon-origin" wx:if="{{item.couponOrigin == '0'}}" src="/image/common/coupon_origin/ic_sjq.png"></image>
        <image class="temp-coupon-origin" wx:if="{{item.couponOrigin == '1'}}" src="/image/common/coupon_origin/ic_ptq.png"></image>
        <image class="temp-coupon-origin" wx:if="{{item.couponOrigin == '2'}}" src="/image/common/coupon_origin/ic_ysf.png"></image>
        <image class="temp-coupon-origin" wx:if="{{item.couponOrigin == '3'}}" src="/image/common/coupon_origin/ic_wxq.png"></image>
        <image class="temp-coupon-origin" wx:if="{{item.couponOrigin == '4'}}" src="/image/common/coupon_origin/ic_zfb.png"></image>
        <image class="temp-coupon-origin" wx:if="{{item.couponOrigin == '5'}}" src="/image/common/coupon_origin/ic_zjq.png"></image> -->
                        <!-- couponOrigin0或者空自建券(couponSource等于1是商家 2是平台) 1是微信券 2云闪付券 -->
                        <image
                            class="temp-coupon-origin"
                            v-if="(item.couponOrigin == '0' || item.couponOrigin == '') && (item.couponSource == '1' || item.couponSource == '7')"
                            src="/static/image/common/coupon_origin/ic_sjq.png"
                        ></image>
                        <image
                            class="temp-coupon-origin"
                            v-if="(item.couponOrigin == '0' || item.couponOrigin == '') && item.couponSource == '2'"
                            src="/static/image/common/coupon_origin/ic_ptq.png"
                        ></image>
                        <image class="temp-coupon-origin" v-if="item.couponOrigin == '1'" src="/static/image/common/coupon_origin/ic_wxq.png"></image>
                        <image class="temp-coupon-origin" v-if="item.couponOrigin == '2'" src="/static/image/common/coupon_origin/ic_ysf.png"></image>
                        <image class="temp-coupon-origin" v-if="item.couponOrigin == '3'" src="/static/image/common/coupon_origin/ic_zfb.png"></image>
                        <image class="temp-coupon-origin" v-if="item.couponOrigin == '0' && item.couponSource == '6'" src="/static/image/common/coupon_origin/ic_zjq.png"></image>
                        <view class="temp-coupon-discount-info" v-if="'7' != item.couponType">
                            <block v-if="'1' == item.couponType || '3' == item.couponType || '5' == item.couponType || '6' == item.couponType">
                                <text class="temp-icon-price">￥</text>
                                <text class="temp-icon-discount" v-if="item.discountLength == 5" style="font-size: 44rpx">{{ util.formatFenMoney(item.discountAmt) }}</text>
                                <text class="temp-icon-discount" v-else-if="item.discountLength == 6" style="font-size: 36rpx">{{ util.formatFenMoney(item.discountAmt) }}</text>
                                <text class="temp-icon-discount" v-else-if="item.discountLength >= 7" style="font-size: 32rpx">{{ util.formatFenMoney(item.discountAmt) }}</text>
                                <text class="temp-icon-discount" v-else>{{ util.formatFenMoney(item.discountAmt) }}</text>
                            </block>
                            <block v-if="'2' == item.couponType || '4' == item.couponType">
                                <text class="temp-icon-discount">{{ item.discountAmt }}</text>
                                <text class="temp-icon-price">折</text>
                            </block>
                        </view>
                    </view>

                    <view class="temp-coupon-item-middle">
                        <view class="temp-coupon-tips" v-if="item.couponOrigin == '1' && item.usedTips">{{ item.usedTips }}</view>
                        <view class="temp-coupon-middle-top">
                            <text class="temp-coupon-name" v-if="'6' == item.couponType || '7' == item.couponType">
                                {{ undefined != item.couponName ? item.couponName : item.name }}
                            </text>
                            <text class="temp-coupon-name" v-else>满{{ util.formatFenMoney(item.useCondAmt) }}元可用</text>
                            <text class="temp-coupon-type reduce" v-if="item.couponType == '1' || '3' == item.couponType || '5' == item.couponType">满减券</text>
                            <text class="temp-coupon-type" v-if="item.couponType == '2' || '4' == item.couponType">折扣券</text>
                            <text class="temp-coupon-type reduce" v-if="'6' == item.couponType">代金券</text>
                            <text class="temp-coupon-type reduce" v-if="'7' == item.couponType">兑换券</text>
                        </view>
                        <view class="temp-coupon-middle-bottom">
                            <view v-if="item.expireDateType == 1">活动期至{{ item.expireEndTime }}</view>
                            <view v-if="item.expireDateType == 2">领取后{{ item.expireDaysNum }}天有效</view>
                        </view>
                    </view>

                    <block v-if="item.qrcode">
                        <view class="temp-coupon-item-right" :data-coupon="item" @tap.stop.prevent="goToCoupon">
                            <view class="temp-coupon-right-get">{{ couponCodeStatus == 1 ? '立即使用' : '查看' }}</view>
                        </view>
                    </block>

                    <block v-else>
                        <view class="temp-coupon-item-right" v-if="item.isFree" :data-coupon="item" @tap.stop.prevent="goToCoupon">
                            <view class="temp-coupon-right-get" v-if="couponBtnText != null">{{ couponBtnText }}</view>
                            <view class="temp-coupon-right-get" v-else-if="item.isLineIssuedStamps != '1'">立即领取</view>
                            <view v-else>扫码领取</view>
                        </view>
                        <view class="temp-coupon-item-right" v-if="!item.isFree" :data-coupon="item" @tap.stop.prevent="goToCoupon">
                            <view class="temp-coupon-buy-price" v-if="item.exchangeType == 1">
                                <text>{{ item.exchangePoint }}</text>
                                <text>积分</text>
                            </view>
                            <view class="temp-coupon-buy-price" v-if="item.exchangeType == 2">
                                <text>￥</text>
                                <text>{{ item.exchangePrice }}</text>
                            </view>
                            <view class="temp-coupon-buy-price temp-price-point" v-if="item.exchangeType == 3">
                                <text style="font-size: 28rpx; font-weight: 600">{{ item.exchangePoint }}</text>
                                <text style="font-size: 18rpx">积分</text>
                                <text style="font-size: 18rpx">+</text>
                                <text style="font-size: 18rpx">￥</text>
                                <text style="font-size: 28rpx; font-weight: 600">{{ item.exchangePrice }}</text>
                            </view>
                            <view class="temp-coupon-right-get" v-if="couponBtnText != null">{{ couponBtnText }}</view>
                            <view class="temp-coupon-right-get" v-else-if="item.isLineIssuedStamps != '1'">去兑换</view>
                            <view v-else>扫码领取</view>
                        </view>
                    </block>
                </view>
            </view>
            <view class="temp-coupon-list" v-else>
                <view class="temp-coupon-empty">
                    <image class="temp-coupon-empty-img" src="/static/image/icon_coupon_empty.png"></image>
                    <text class="temp-coupon-empty-tip">暂无优惠券</text>
                </view>
            </view>
        </block>

        <!-- 优惠券订单列表和普通优惠券订单详情，使用该模板 -->
        <!-- 
传入参数：
couponOrder：订单详情
showOrderType：是否显示订单类型
 -->
        <block name="coupon-order">
            <view class="temp-coupon-order">
                <view class="temp-coupon-order-left">
                    <image class="temp-coupon-order-left-bg" src="/static/image/coupon/detail_img_card@2x.png"></image>
                    <view class="temp-coupon-order-discount-info">
                        <block v-if="'1' == couponOrder.coupon.couponType">
                            <text class="temp-coupon-order-icon-price">￥</text>
                            <text class="temp-coupon-order-icon-discount">{{ util.formatFenMoney(couponOrder.coupon.discountAmt) }}</text>
                        </block>
                        <block v-if="'2' == couponOrder.coupon.couponType">
                            <text class="temp-coupon-order-icon-discount">{{ couponOrder.coupon.discountAmt }}</text>
                            <text class="temp-coupon-order-icon-price">折</text>
                        </block>
                    </view>
                </view>
                <view class="temp-coupon-order-middle">
                    <view class="temp-coupon-order-middle-line1">
                        <text class="temp-order-type" v-if="showOrderType && couponOrder.orderType == 6">拼团</text>
                        <text>{{ couponOrder.couponName }}</text>
                    </view>
                    <view class="temp-coupon-order-middle-line2">
                        <view class="temp-coupon-order-middle-price-info">
                            <block v-if="couponOrder.exchangeRuleType == 1">
                                <text>{{ couponOrder.point }}积分</text>
                                <text></text>
                            </block>
                            <block v-else-if="couponOrder.exchangeRuleType == 2">
                                <text>￥{{ util.formatFenMoney(couponOrder.payAmount) }}</text>
                            </block>
                            <block v-else-if="couponOrder.exchangeRuleType == 3">
                                <text>{{ couponOrder.point }}积分+￥{{ util.formatFenMoney(couponOrder.payAmount) }}</text>
                            </block>
                        </view>
                        <text class="temp-coupon-order-middle-line2-right">x1</text>
                    </view>
                </view>
            </view>
            <view class="temp-coupon-order-total-info">
                共
                <text style="color: #000; font-weight: bold; font-size: 28rpx">1</text>
                件，合计：
                <view class="temp-coupon-order-price-info">
                    <block v-if="couponOrder.exchangeRuleType == 1">
                        <text class="temp-coupon-order-price-font">{{ couponOrder.point }}</text>
                        <text>积分</text>
                    </block>
                    <block v-else-if="couponOrder.exchangeRuleType == 2">
                        <text>￥</text>
                        <text class="temp-coupon-order-price-font">{{ util.formatFenMoney(couponOrder.payAmount) }}</text>
                    </block>
                    <block v-else-if="couponOrder.exchangeRuleType == 3">
                        <text class="temp-coupon-order-price-font">{{ couponOrder.point }}</text>
                        <text>积分+￥</text>
                        <text class="temp-coupon-order-price-font">{{ util.formatFenMoney(couponOrder.payAmount) }}</text>
                    </block>
                    <block v-else>
                        <text>￥</text>
                        <text class="temp-coupon-order-price-font">0</text>
                    </block>
                </view>
            </view>
            <view>
                <block>
                    <view class="temp-coupon-order-btn-box">
                        <view
                            v-if="couponOrder.status == '0'"
                            class="temp-coupon-order-btn"
                            style="border-color: #f12106; color: #f12106"
                            data-type="1"
                            @tap.stop.prevent="addToCart"
                        >
                            立即购买
                        </view>
                        <view
                            class="temp-coupon-order-btn"
                            v-if="1 == couponOrder.orderType"
                            style="border-color: #f12106; color: #f12106"
                            data-type="1"
                            @tap.stop.prevent="addToCart"
                        >
                            <navigator
                                class="coupon-item-right"
                                hover-class="none"
                                :url="'/pages/coupon/couponDetail/couponDetail?couponId=' + couponOrder.couponId + '&saleRuleId=' + couponOrder.saleRuleId"
                            >
                                再次购买
                            </navigator>
                        </view>
                        <view
                            class="temp-coupon-order-btn"
                            v-if="6 == couponOrder.orderType"
                            style="border-color: #f12106; color: #f12106"
                            data-type="1"
                            @tap.stop.prevent="addToCart"
                        >
                            <navigator
                                class="coupon-item-right"
                                hover-class="none"
                                :url="'/couponMarketingPkg/pages/couponGroupBuy/groupBuyDetail/groupBuyDetail?id=' + couponOrder.sid + '&couponId=' + couponOrder.couponId"
                            >
                                再次购买
                            </navigator>
                        </view>
                    </view>
                </block>
            </view>
        </block>

        <!-- 优惠券订单状态 -->
        <!-- 
传入参数：
couponOrder：订单详情
 -->
        <block name="coupon-order-status">
            <block>
                <text v-if="couponOrder.status == '0'">待付款</text>
                <text v-else-if="couponOrder.status == '1'">已付款</text>
                <text v-else-if="couponOrder.status == '2'">待发券</text>
                <text v-else-if="couponOrder.status == '4'">已完成</text>
                <text v-else-if="couponOrder.status == '5'">已核销</text>
                <text v-else-if="couponOrder.status == '6'">已取消</text>
                <text v-else-if="couponOrder.status == '8'">申请退款</text>
                <text v-else-if="couponOrder.status == '9'">已退款</text>
                <text v-else-if="couponOrder.status == '10'">已终止</text>
                <text v-else-if="couponOrder.status == '99'">下单失败</text>
            </block>
        </block>

        <!-- 商品基本样式 -->
        <!-- 
传入参数：
produce：订单详情
baseurl：图片桶名
 -->
        <block name="mall-produce">
            <block>
                <navigator class="mall-produce-box" :url="'/subPackages/mall/pages/goods/goods?goodsId=' + produce.id">
                    <view class="mall-produce-img">
                        <image :src="baseurl + '/' + produce.img"></image>
                    </view>
                    <view class="mall-produce-name">
                        <view>
                            {{ produce.name }}
                        </view>

                        <view class="mall-produce-bottom">
                            <view class="mall-produce-price">￥{{ produce.price }}</view>
                            <view>
                                <view class="shop-car-icon" @tap.stop.prevent="addGoods" :data-goodsid="produce.id">
                                    <image src="/static/image/shop-car.png"></image>
                                </view>
                            </view>
                        </view>
                    </view>
                </navigator>
            </block>
        </block>

        <!-- 抽奖结果弹窗 -->
        <!-- 
传入参数：
baseImageUrl：图片路径的前缀；
giftContent：礼包内容
绑定方法：
onCloseResult：关闭弹窗的方法
 -->
        <block name="lottery-result-pop">
            <view class="temp-pop-container">
                <image class="temp-pop-bg" :src="baseImageUrl + '/lottery/wheel-pop-bg@2x.png'" style="width: 100%; height: 888rpx" mode="widthFix"></image>
                <view class="temp-pop-content" v-if="giftContent.giftCoupons || giftContent.point">
                    <view class="temp-content-title">恭喜您中奖了</view>
                    <view class="temp-content-reward">{{ giftContent.name }}</view>
                    <view style="display: flex; justify-content: center">
                        <view class="temp-content-reward-list">
                            <view class="temp-content-reward-item" v-if="giftContent.point > 0">
                                <image :src="baseImageUrl + '/lottery/wheel-pop-pointgift@2x.png'" style="width: 112rpx; height: 88rpx"></image>
                                <view class="temp-reward-name">赠送{{ giftContent.point }}积分</view>
                            </view>
                            <block v-for="(coupon, index) in giftContent.giftCoupons" :key="index">
                                <view class="temp-content-reward-item" v-if="coupon.couponType == '1'">
                                    <image :src="baseImageUrl + '/lottery/wheel-pop-coupon1@2x.png'" style="width: 112rpx; height: 88rpx"></image>
                                    <view class="temp-reward-name">满减券{{ coupon.couponNo }}张</view>
                                </view>

                                <view class="temp-content-reward-item" v-if="coupon.couponType == '2'">
                                    <image :src="baseImageUrl + '/lottery/wheel-pop-coupon2@2x.png'" style="width: 112rpx; height: 88rpx"></image>
                                    <view class="temp-reward-name">折扣券{{ coupon.couponNo }}张</view>
                                </view>
                            </block>
                        </view>
                    </view>
                    <navigator class="temp-content-reward-btn" :url="'/subPackages/lottery/pages/giftPkgDetail/giftPkgDetail?id=' + giftContent.id">
                        <image :src="baseImageUrl + '/lottery/wheel-pop-btn@2x.png'" style="width: 100%; height: 100rpx"></image>
                        <view>查看更多</view>
                    </navigator>
                </view>
                <view class="temp-pop-content-fail" v-else>
                    <image class="temp-content-fail-img" :src="baseImageUrl + '/lottery/wheel-fail.png'"></image>
                    <view class="temp-content-fail-line1">谢谢参与</view>
                    <view class="temp-content-fail-line2">本次未抽中奖品哦～</view>
                    <view class="temp-content-reward-btn" @tap="onCloseResult">
                        <image :src="baseImageUrl + '/lottery/wheel-pop-btn@2x.png'" style="width: 100%; height: 100rpx"></image>
                        <view v-if="limitNum > 0" @tap.stop.prevent="onceMore">再来一次</view>
                        <view v-else>谢谢参与</view>
                    </view>
                </view>
                <image class="temp-pop-close" :src="baseImageUrl + '/lottery/wheel-pop-close@2x.png'" style="width: 160rpx; height: 160rpx" @tap="onCloseResult"></image>
            </view>
        </block>
    </view>
</template>
<script module="util" lang="wxs">
function formatFenMoney(s) {
  if (undefined == s || '' == s || null == s) {
    return 0;
  } else {
    return s / 100
  }
}

function isEmpty(s) {
return undefined == s || '' == s || null == s;
}

module.exports = {
  formatFenMoney: formatFenMoney,
  isEmpty: isEmpty
}
</script>

<style>
@import './zsnshTemplates.css';
</style>
